<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>用户注册</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <link rel="stylesheet" href="../js/lay-module/step-lay/step.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-card-body" style="padding-top: 40px;">
                    <div class="layui-carousel" id="stepForm" lay-filter="stepForm" style="margin: 0 auto;">
                        <div carousel-item>
                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">账号昵称</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="userName" placeholder="请填写账号昵称" class="layui-input"  lay-verify="required" lay-reqtext="昵称不能为空" />

                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">账号</label>
                                        <div class="layui-input-block">
                                            <input id="account" type="text" name="userAccountNumber" placeholder="请填写账号" value="" class="layui-input"  lay-verify="required" lay-reqtext="账号不能为空">
                                        </div>
                                    </div>
									<div class="layui-form-item">
									    <label class="layui-form-label">密码</label>
									    <div class="layui-input-block">
									        <input type="password" name="userPassword" placeholder="请输入密码" autocomplete="off" class="layui-input">
									    </div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">邮箱</label>
										<div class="layui-input-inline" style="width: 60%">
								        <input type="text" name="email"  lay-verify="email" placeholder="请填写邮箱" autocomplete="off" class="layui-input">
										</div>
									</div>

                                    <div class="layui-form-item" >

                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button class="layui-btn" lay-submit lay-filter="formStep">
                                                &emsp;完成信息填写，以进行下一步&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                    <div class="layui-form-item">
                                        <!--<label class="layui-form-label">输入框</label>-->
                                        <label class="layui-icon layui-icon-vercode layui-form-label formslabel" ></label>
                                        <!--<div class="layui-input-block formsinput">-->
                                        <input type="text" name="mailcaptcha"  required  lay-verify="required" placeholder="邮箱验证码" autocomplete="off" class="layui-input formsinput " style="float: left;width: 40%;margin-right: 14px;">
                                        <!--</div>-->
                                        <div class="layui-col-xs3">  <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid" onclick="mail()" name="btnSendCode" id="btnSendCode">获取验证码</button>  </div>
                                    </div>
                                    
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button type="button" class="layui-btn layui-btn-primary pre">上一步</button>
                                            <button class="layui-btn" lay-submit="" lay-filter="formStep2">
                                                &emsp;点击注册&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div>
                                <div style="text-align: center;margin-top: 90px;">
                                    <i class="layui-icon layui-circle"
                                       style="color: white;font-size:30px;font-weight:bold;background: #52C41A;padding: 20px;line-height: 80px;">&#xe605;</i>
                                    <div style="font-size: 24px;color: #333;font-weight: 500;margin-top: 30px;">
                                        注册成功
                                    </div>
                                    <div style="font-size: 14px;color: #666;margin-top: 20px;">请尝试登录吧</div>
                                </div>
                                <div style="text-align: center;margin-top: 50px;">

                                    <a href="/login" class="layui-btn">点我去到登录页</a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <hr>
                    <div style="color: #666;margin-top: 30px;margin-bottom: 40px;padding-left: 30px;">
                        <h3>说明</h3><br>
                        <h4>注册</h4>
                        <p>注册成功后，可选择自己喜欢的社团进行申请</p>
                        <br><h4>申请入社</h4>
                        <p>当社长确认申请信息，同意入社后，即可完成入社程序</p>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use([ 'form', 'step'], function () {
        var $ = layui.$,
            form = layui.form,
            step = layui.step,
            $=layui.$;

        step.render({
            elem: '#stepForm',
            filter: 'stepForm',
            width: '100%', //设置容器宽度
            stepWidth: '750px',
            height: '500px',
            stepItems: [{
                title: '注册'
            }, {
                title: '安全验证'
            }, {
                title: '完成注册'
            }]
        });


        form.on('submit(formStep)', function (data) {
            var userInfo = data.field;
            var url = "/user/add";
            $.ajax({
                url:url,
                type:'post',
                data:userInfo,
                success:function(data){
                    if(data.msg== 'success'){
                        step.next('#stepForm');
                    }else if(data.msg== 'failure') {

                        $('#account').addClass('layui-form-danger').focus();
                        layer.msg('账号验证失败，账号已存在！', {undefined,
                            icon: 5
                        });
                    }else {
                        layer.msg("提交失败，请检查网络，或稍后再试！");
                    }
                }
            });


            return false;
        });

        form.on('submit(formStep2)', function (data) {
            step.next('#stepForm');
            return false;
        });

        $('.pre').click(function () {
            step.pre('#stepForm');
        });

        $('.next').click(function () {
            step.next('#stepForm');
        });
    })
</script>
<script>

    var $ = layui.jquery,element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
    var form = layui.form;


    var InterValObj; //timer变量，控制时间
    var count = 60; //间隔函数，1秒执行
    var curCount;//当前剩余秒数
    //发送验证码
    function mail(){
        curCount = count;
        var email = $('#email').val();
        layer.msg("发送成功，请稍后！", {
            icon: 1,
            time: 1000
        });

        document.getElementById("btnSendCode").setAttribute("disabled","true" );//设置按钮为禁用状态
        $('#btnSendCode').addClass('layui-btn-disabled');
        $('#btnSendCode').text(curCount + "秒后重获");
        InterValObj = window.setInterval(SetRemainTime, 1000); // 启动计时器timer处理函数，1秒执行一次
        $.ajax({
            url:"",
            data:{},
            type:"Post",
            dataType:"json",
            success:function(data){


            },
            error:function(data){
                $.messager.alert('错误',data.msg);
            }
        });

    }

    //timer处理函数
    function SetRemainTime(){
        if(curCount == 0){
            $('#btnSendCode').removeClass('layui-btn-disabled');
            $('#btnSendCode').text("重获验证码");
            window.clearInterval(InterValObj);// 停止计时器
            document.getElementById("btnSendCode").removeAttribute("disabled");//移除禁用状态改为可用
        } else{
            curCount--;
            $('#btnSendCode').text(curCount + "秒后重获");
        }
    }



</script>
</body>
</html>